package com.example.jobback.controller.websocket;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: WebSocketDocController
 * @Description: websocket文档说明控制器
 * @Author: lhb
 * @Date: 2025/5/24
 */

@RestController
@Tag(name = "webSocket接口说明", description = "聊天通知的WebSocket端点")
public class WebSocketDocController {

    @GetMapping("/websocket-doc/endpoint")
    @Operation(summary = "WebSocket连接信息", description = """
        **WebSocket Endpoint**: `ws://ip地址:8084/message?token=your_token`  
        **协议**:  
        - 这里的token前面不需要Bearer前缀，也不建议加  
        - 连接后通过发送JSON消息进行通信  
        """)
    public String websocketEndpoint() {
        return "WebSocket连接信息";
    }

    @GetMapping("/websocket-doc/chat-record-manager")
    @Operation(summary = "管理员-聊天记录消息格式", description = """
        **聊天记录消息格式示例**：
        ```json
        {
                  "createdAt": "2025-05-29 21:48:19.126311600",
                  "fromRole": "server",
                  "fromUserId": -1,
                  "message": [
                      {
                          "contactUserId": 5,
                          "messageSendRespList": [
                              {
                                  "createdAt": "2025-05-25 14:30:00",
                                  "fromRole": "manager",
                                  "fromUserId": 2,
                                  "message": "你好",
                                  "messageType": "TEXT",
                                  "online": true,
                                  "toRole": "manager",
                                  "toUserId": 5
                              },
                              {
                                  "createdAt": "2025-05-25 14:30:00",
                                  "fromRole": "manager",
                                  "fromUserId": 2,
                                  "message": "你好",
                                  "messageType": "TEXT",
                                  "online": true,
                                  "toRole": "manager",
                                  "toUserId": 5
                              },
                              {
                                  "createdAt": "2025-05-25 14:30:00",
                                  "fromRole": "manager",
                                  "fromUserId": 2,
                                  "message": "你好",
                                  "messageType": "TEXT",
                                  "online": true,
                                  "toRole": "manager",
                                  "toUserId": 5
                              },
                              {
                                  "createdAt": "2025-05-25 14:30:00",
                                  "fromRole": "manager",
                                  "fromUserId": 2,
                                  "message": "你好",
                                  "messageType": "TEXT",
                                  "online": true,
                                  "toRole": "manager",
                                  "toUserId": 5
                              },
                              {
                                  "createdAt": "2025-05-25 14:30:00",
                                  "fromRole": "manager",
                                  "fromUserId": 2,
                                  "message": "你好",
                                  "messageType": "TEXT",
                                  "online": true,
                                  "toRole": "manager",
                                  "toUserId": 5
                              },
                              {
                                  "createdAt": "2025-05-25 14:30:00",
                                  "fromRole": "manager",
                                  "fromUserId": 2,
                                  "message": "你好",
                                  "messageType": "TEXT",
                                  "online": true,
                                  "toRole": "manager",
                                  "toUserId": 5
                              }
                          ],
                          "role": "manager"
                      },
                      {
                          "contactUserId": 6,
                          "messageSendRespList": [
                              {
                                  "createdAt": "2025-05-25 14:30:00",
                                  "fromRole": "manager",
                                  "fromUserId": 2,
                                  "message": "你好",
                                  "messageType": "TEXT",
                                  "online": true,
                                  "toRole": "manager",
                                  "toUserId": 6
                              }
                          ],
                          "role": "manager"
                      },
                      {
                          "contactUserId": 3,
                          "messageSendRespList": [
                              {
                                  "createdAt": "2025-04-24 00:20:21",
                                  "fromRole": "manager",
                                  "fromUserId": 3,
                                  "message": "3对2说",
                                  "messageType": "TEXT",
                                  "online": true,
                                  "toRole": "manager",
                                  "toUserId": 2
                              },
                              {
                                  "createdAt": "2025-05-22 00:19:37",
                                  "fromRole": "manager",
                                  "fromUserId": 2,
                                  "message": "2对3说",
                                  "messageType": "TEXT",
                                  "online": false,
                                  "toRole": "manager",
                                  "toUserId": 3
                              }
                          ],
                          "role": "manager"
                      },
                      {
                          "contactUserId": 4,
                          "messageSendRespList": [
                              {
                                  "createdAt": "2025-05-01 00:18:01",
                                  "fromRole": "manager",
                                  "fromUserId": 4,
                                  "message": "4对2说",
                                  "messageType": "TEXT",
                                  "online": true,
                                  "toRole": "manager",
                                  "toUserId": 2
                              },
                              {
                                  "createdAt": "2025-05-27 10:54:11",
                                  "fromRole": "manager",
                                  "fromUserId": 2,
                                  "message": "2对4说",
                                  "messageType": "TEXT",
                                  "online": true,
                                  "toRole": "manager",
                                  "toUserId": 4
                              }
                          ],
                          "role": "manager"
                      }
                  ],
                  "messageType": "CHAT_RECORD",
                  "online": true,
                  "toRole": "manager",
                  "toUserId": 2
              }
        ```
        """)
    public String chatRecordManager() {
        return "聊天记录消息格式";
    }

    @GetMapping("/websocket-doc/chat-record-seeker")
    @Operation(summary = "求职者-聊天记录消息格式", description = """
        **聊天记录消息格式示例**：
        ```json
              {
                      "createdAt": "2025-07-22 16:54:16.837645200",
                      "fromRole": "server",
                      "fromUserId": -1,
                      "message": [
                          {
                              "contactUserId": 5,
                              "messageSendRespList": [
                                  {
                                      "createdAt": "2025-05-25 14:30:00",
                                      "fromRole": "recruiter",
                                      "fromUserId": 5,
                                      "message": "发送测试",
                                      "messageType": "TEXT",
                                      "online": true,
                                      "toRole": "seeker",
                                      "toUserId": 3
                                  }
                              ],
                              "role": "recruiter",
                              "userRelatedMessageResp": {
                                  "avatar": "https://boss-v1.oss-cn-hangzhou.aliyuncs.com/Avatar/Default/user.jpg",
                                  "companyName": "美图秀秀科技有限公司",
                                  "name": "王志宇",
                                  "role": "boss",
                                  "userId": 5
                              }
                          },
                          {
                              "contactUserId": 2,
                              "messageSendRespList": [
                                  {
                                      "createdAt": "2025-05-25 14:30:00",
                                      "fromRole": "recruiter",
                                      "fromUserId": 2,
                                      "message": "测试一下有没有用户记录",
                                      "messageType": "TEXT",
                                      "online": true,
                                      "toRole": "seeker",
                                      "toUserId": 3
                                  },
                                  {
                                      "createdAt": "2025-05-25 14:30:00",
                                      "fromRole": "recruiter",
                                      "fromUserId": 2,
                                      "message": "测试一下有没有用户记录2",
                                      "messageType": "TEXT",
                                      "online": true,
                                      "toRole": "seeker",
                                      "toUserId": 3
                                  },
                                  {
                                      "createdAt": "2025-05-25 14:30:00",
                                      "fromRole": "recruiter",
                                      "fromUserId": 2,
                                      "message": "测试一下有没有用户记录2",
                                      "messageType": "TEXT",
                                      "online": true,
                                      "toRole": "seeker",
                                      "toUserId": 3
                                  },
                                  {
                                      "createdAt": "2025-05-25 14:30:00",
                                      "fromRole": "recruiter",
                                      "fromUserId": 2,
                                      "message": "测试一下有没有用户记录3",
                                      "messageType": "TEXT",
                                      "online": true,
                                      "toRole": "seeker",
                                      "toUserId": 3
                                  },
                                  {
                                      "createdAt": "2025-05-25 14:30:00",
                                      "fromRole": "recruiter",
                                      "fromUserId": 2,
                                      "message": "测试一下有没有用户记录3",
                                      "messageType": "TEXT",
                                      "online": true,
                                      "toRole": "seeker",
                                      "toUserId": 3
                                  },
                                  {
                                      "createdAt": "2025-05-25 14:30:00",
                                      "fromRole": "seeker",
                                      "fromUserId": 3,
                                      "message": "测试一下有没有用户记录4",
                                      "messageType": "TEXT",
                                      "online": true,
                                      "toRole": "recruiter",
                                      "toUserId": 2
                                  },
                                  {
                                      "createdAt": "2025-05-25 14:30:00",
                                      "fromRole": "recruiter",
                                      "fromUserId": 2,
                                      "message": "测试一下有没有用户记录3",
                                      "messageType": "TEXT",
                                      "online": true,
                                      "toRole": "seeker",
                                      "toUserId": 3
                                  },
                                  {
                                      "createdAt": "2025-05-25 14:30:00",
                                      "fromRole": "recruiter",
                                      "fromUserId": 2,
                                      "message": "测试一下有没有用户记录3",
                                      "messageType": "TEXT",
                                      "online": true,
                                      "toRole": "seeker",
                                      "toUserId": 3
                                  },
                                  {
                                      "createdAt": "2025-05-25 14:30:00",
                                      "fromRole": "recruiter",
                                      "fromUserId": 2,
                                      "message": "发送测试",
                                      "messageType": "TEXT",
                                      "online": true,
                                      "toRole": "seeker",
                                      "toUserId": 3
                                  },
                                  {
                                      "createdAt": "2025-05-25 14:30:00",
                                      "fromRole": "seeker",
                                      "fromUserId": 3,
                                      "message": "我是求职者",
                                      "messageType": "TEXT",
                                      "online": true,
                                      "toRole": "recruiter",
                                      "toUserId": 2
                                  }
                              ],
                              "role": "recruiter",
                              "userRelatedMessageResp": {
                                  "avatar": "https://boss-v1.oss-cn-hangzhou.aliyuncs.com/Avatar/User/2.jpg",
                                  "companyName": "南京云计算服务有限公司",
                                  "name": "张三",
                                  "role": "boss",
                                  "userId": 2
                              }
                          }
                      ],
                      "messageType": "CHAT_RECORD",
                      "online": true,
                      "toRole": "seeker",
                      "toUserId": 3
                  }
        ```
        """)
    public String chatRecordSeeker() {
        return "聊天记录消息格式";
    }

    @GetMapping("/websocket-doc/chat-record-recruiter")
    @Operation(summary = "招聘者-聊天记录消息格式", description = """
        **聊天记录消息格式示例**：
        ```json
            {
                         "createdAt": "2025-07-22 16:49:52.890264",
                         "fromRole": "server",
                         "fromUserId": -1,
                         "message": [
                             {
                                 "contactUserId": 32,
                                 "messageSendRespList": [
                                     {
                                         "createdAt": "2025-05-25 14:30:00",
                                         "fromRole": "seeker",
                                         "fromUserId": 32,
                                         "message": "我是求职者",
                                         "messageType": "TEXT",
                                         "online": false,
                                         "toRole": "recruiter",
                                         "toUserId": 2
                                     }
                                 ],
                                 "role": "seeker",
                                 "userRelatedMessageResp": {
                                     "avatar": "https://boss-v1.oss-cn-hangzhou.aliyuncs.com/Avatar/Default/user.jpg",
                                     "name": "用户6219112",
                                     "userId": 32
                                 }
                             },
                             {
                                 "contactUserId": 3,
                                 "messageSendRespList": [
                                     {
                                         "createdAt": "2025-05-25 14:30:00",
                                         "fromRole": "recruiter",
                                         "fromUserId": 2,
                                         "message": "测试一下有没有用户记录",
                                         "messageType": "TEXT",
                                         "online": true,
                                         "toRole": "seeker",
                                         "toUserId": 3
                                     },
                                     {
                                         "createdAt": "2025-05-25 14:30:00",
                                         "fromRole": "recruiter",
                                         "fromUserId": 2,
                                         "message": "测试一下有没有用户记录2",
                                         "messageType": "TEXT",
                                         "online": true,
                                         "toRole": "seeker",
                                         "toUserId": 3
                                     },
                                     {
                                         "createdAt": "2025-05-25 14:30:00",
                                         "fromRole": "recruiter",
                                         "fromUserId": 2,
                                         "message": "测试一下有没有用户记录2",
                                         "messageType": "TEXT",
                                         "online": true,
                                         "toRole": "seeker",
                                         "toUserId": 3
                                     },
                                     {
                                         "createdAt": "2025-05-25 14:30:00",
                                         "fromRole": "recruiter",
                                         "fromUserId": 2,
                                         "message": "测试一下有没有用户记录3",
                                         "messageType": "TEXT",
                                         "online": true,
                                         "toRole": "seeker",
                                         "toUserId": 3
                                     },
                                     {
                                         "createdAt": "2025-05-25 14:30:00",
                                         "fromRole": "recruiter",
                                         "fromUserId": 2,
                                         "message": "测试一下有没有用户记录3",
                                         "messageType": "TEXT",
                                         "online": true,
                                         "toRole": "seeker",
                                         "toUserId": 3
                                     },
                                     {
                                         "createdAt": "2025-05-25 14:30:00",
                                         "fromRole": "seeker",
                                         "fromUserId": 3,
                                         "message": "测试一下有没有用户记录4",
                                         "messageType": "TEXT",
                                         "online": true,
                                         "toRole": "recruiter",
                                         "toUserId": 2
                                     },
                                     {
                                         "createdAt": "2025-05-25 14:30:00",
                                         "fromRole": "recruiter",
                                         "fromUserId": 2,
                                         "message": "测试一下有没有用户记录3",
                                         "messageType": "TEXT",
                                         "online": true,
                                         "toRole": "seeker",
                                         "toUserId": 3
                                     },
                                     {
                                         "createdAt": "2025-05-25 14:30:00",
                                         "fromRole": "recruiter",
                                         "fromUserId": 2,
                                         "message": "测试一下有没有用户记录3",
                                         "messageType": "TEXT",
                                         "online": true,
                                         "toRole": "seeker",
                                         "toUserId": 3
                                     },
                                     {
                                         "createdAt": "2025-05-25 14:30:00",
                                         "fromRole": "recruiter",
                                         "fromUserId": 2,
                                         "message": "发送测试",
                                         "messageType": "TEXT",
                                         "online": true,
                                         "toRole": "seeker",
                                         "toUserId": 3
                                     },
                                     {
                                         "createdAt": "2025-05-25 14:30:00",
                                         "fromRole": "seeker",
                                         "fromUserId": 3,
                                         "message": "我是求职者",
                                         "messageType": "TEXT",
                                         "online": true,
                                         "toRole": "recruiter",
                                         "toUserId": 2
                                     }
                                 ],
                                 "role": "seeker",
                                 "userRelatedMessageResp": {
                                     "avatar": "https://boss-v1.oss-cn-hangzhou.aliyuncs.com/Avatar/User/3.jpg",
                                     "name": "李四",
                                     "userId": 3
                                 }
                             }
                         ],
                         "messageType": "CHAT_RECORD",
                         "online": true,
                         "toRole": "recruiter",
                         "toUserId": 2
                     }
        ```
        """)
    public String chatRecordRecruiter() {
        return "聊天记录消息格式";
    }

    @GetMapping("/websocket-doc/sender-example")
    @Operation(summary = "发送者消息格式", description = """
        **发送者消息格式示例**：
        ```json
        {
            "fromUserId": 2,
            "toUserId": 5,
            "fromRole": "seeker",
            "toRole": "recruiter",
            "message": "你好我是求职者",
            "messageType": "TEXT",
            "createdAt": "2025-05-25T14:30:00"
        }
        ```
        """)
    public String senderExample() {
        return "发送者消息格式";
    }

    @GetMapping("/websocket-doc/receiver-example-manager")
    @Operation(summary = "管理员-接收者消息格式", description = """
        **接收者消息格式示例**：
        ```json
        {
            "createdAt": "2025-05-25 14:30:00",
            "fromRole": "manager",
            "fromUserId": 2,
            "message": "你好我是管理员",
            "messageType": "TEXT",
            "online": true,
            "toRole": "manager",
            "toUserId": 5
        }
        ```
        """)
    public String receiverExampleManager() {
        return "接收者消息格式";
    }

    @GetMapping("/websocket-doc/receiver-example-seeker")
    @Operation(summary = "求职者-接收者消息格式", description = """
        **接收者消息格式示例**：
        ```json
            {
                "createdAt": "2025-05-25 14:30:00",
                "fromRole": "recruiter",
                "fromUserId": 2,
                "message": "发送测试",
                "messageType": "TEXT",
                "online": true,
                "toRole": "seeker",
                "toUserId": 3,
                "userRelatedMessageResp": {
                    "avatar": "https://boss-v1.oss-cn-hangzhou.aliyuncs.com/Avatar/User/2.jpg",
                    "companyName": "南京云计算服务有限公司",
                    "name": "张三",
                    "role": "boss",
                    "userId": 2
                }
            }
        ```
        """)
    public String receiverExampleSeeker() {
        return "接收者消息格式";
    }

    @GetMapping("/websocket-doc/receiver-example-recruiter")
    @Operation(summary = "招聘者-接收者消息格式", description = """
        **接收者消息格式示例**：
        ```json
            {
                "createdAt": "2025-05-25 14:30:00",
                "fromRole": "seeker",
                "fromUserId": 3,
                "message": "我是求职者",
                "messageType": "TEXT",
                "online": true,
                "toRole": "recruiter",
                "toUserId": 2,
                "userRelatedMessageResp": {
                    "avatar": "https://boss-v1.oss-cn-hangzhou.aliyuncs.com/Avatar/User/3.jpg",
                    "name": "李四",
                    "userId": 3
                }
            }
        ```
        """)
    public String receiverExampleRecruiter() {
        return "接收者消息格式";
    }

    @GetMapping("/websocket-doc/online-users")
    @Operation(summary = "在线用户消息格式", description = """
        **在线用户消息格式示例**：
        ```json
        {
            "createdAt": "2025-07-12 13:04:21.952911200",
            "fromRole": "server",
            "fromUserId": -1,
            "message": {
                2: "manager",
                3: "manager"
            },
            "messageType": "ONLINE_USERS",
            "online": true,
            "toRole": "server",
            "toUserId": -1
        }
        ```
        """)
    public String onlineUsers() {
        return "在线用户消息格式";
    }

    @GetMapping("/websocket-doc/error-message")
    @Operation(summary = "异常消息格式", description = """
        **异常消息格式示例**：
        ```json
        {
            "createdAt": "2025-05-29 22:27:06.491545",
            "message": "token缺失",
            "messageType": "ERROR"
        }
        ```
        """)
    public String errorMessage() {
        return "异常消息格式";
    }

    @GetMapping("/websocket-doc/remote-login-error")
    @Operation(summary = "异地登录消息格式", description = """
        **异地登录消息格式示例**：
        ```json
        {
            "createdAt": "2025-07-12 13:24:14.203605800",
            "message": "异地登录",
            "messageType": "REMOTE_LOGIN_ERROR"
        }
        ```
        """)
    public String remoteLoginError() {
        return "异地登录消息格式";
    }
}
